using System;
using RollManager.Library.Utils;
using System.Xml.Serialization;

namespace RollManager.Library
{
    [Serializable]
    public abstract class PermissionsItemBase : ItemBase
    {
        public int OwnerId;
        public int PermissionId;
        public string OwnerName;

        [XmlIgnore]
        public Permission Permission
        {
            get
            {
                return (Permission) PermissionId;
            }
            set
            {
                PermissionId = (int) value;
            }
        }

        public bool Saveable
        {
            get
            {
                return UserOwned || Permission == Permission.Public;
            }
        }

        [XmlIgnore]
        public bool UserOwned
        {
            get
            {
                return OwnerId == Common.UserId || OwnerId == 0;
            }
        }

        protected void CopyTo( PermissionsItemBase newItem )
        {
            base.CopyTo( newItem );
            newItem.OwnerId = OwnerId;
            newItem.PermissionId = PermissionId;
            newItem.OwnerName = OwnerName;
        }
    }
}
